{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>商品列表</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
            </div>
        </div>
        <div class="ibox-content">
            <div class="row">
                <div class="col-sm-12">
                    <div  class="col-sm-3">
                        <div class="input-group" >
                            <a href="{:url('add')}">
                                <button type="button" class="btn btn-primary btn-outline"  >
                                    <i class="fa fa-plus"></i> 商品添加
                                </button>
                            </a>
                        </div>
                    </div>
                    <div class="col-sm-9">
                        <form id="layuiForm">
                            <div class="col-sm-6">
                                <div class="input-group" >
                                    <input type="text"  name="start" onfocus="wk.lay_date(this);" class="layui-input layer-date search" placeholder="上市开始日期"/>
                                    <span class="input-group-addon">到</span>
                                    <input type="text"  name="end" onfocus="wk.lay_date(this);"  class="layui-input layer-date search" placeholder="上市结束日期"/>
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="input-group" >
                                    <input type="text" id="key" class="form-control search" name="key" value="" placeholder="名称"/>
                                    <span class="input-group-btn">
                                        <a  class="btn btn-primary layuiBtn" data-type="reload"><i class="fa fa-search"></i> 搜索</a>
                                    </span>
                                </div>
                            </div>
                        </form>

                    </div>
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="example-wrap">
                <div class="example">
                    <table class="layui-hide" id="test" lay-filter="testReload"></table>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    layui.use('table', function () {
        var table = layui.table
                , form = layui.form;
        table.render({
            elem: '#test'
            , url: '{:url("shop/index")}'
            , page: true
            , even: false //开启隔行背景
            , size: 'lg' //sm小尺寸的表格 lg大尺寸
            // ,width:100
            , cellMinWidth: 80
            , limits: [5, 10, 15, 20, 25, 30]
            , limit: "{:config('pages')}"
            , text: {
                none: '暂无数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
            }
            , loading: true
            , id: 'testReload'
            , cols: [[
                {type: 'checkbox', fixed: 'left',}
                , {type:'numbers', width: 60, title: '序号'}
                , {field: 'good_id', width:'' , title: 'ID', sort: true, align: 'center'}
                , {field: 'good_name', width: '', title: '商品名称', align: 'center'}
                , {field: 'good_price', width: '', title: '用户端价格', align: 'center'}
                , {field: 'y_price', width: '', title: '运行端价格', align: 'center'}
                , {field: 'good_huohao', width: '', title: '型号', align: 'center'}
                , {field: 'good_guige', width: '', title: '规格', align: 'center'}
                , {field: 'good_chang', width: '', title: '长', align: 'center'}
                , {field: 'good_kuan', width: '', title: '宽', align: 'center'}
                , {field: 'good_gao', width: '', title: '高', align: 'center'}
                , {field: 'good_mao', width: '', title: '毛重', align: 'center'}
                , {field: 'good_jing', width: '', title: '净重', align: 'center'}
                , {field: 'good_hot', width: 130, title: '是否热门', align: 'center',templet:"#good_hot"}
                , {field: 'good_top', width: 130, title: '是否精品', align: 'center',templet:"#good_top"}
                , {field: 'good_create_time', width: '', title: '创建时间', align: 'center'}
                , {field: 'good_thumb', width: '', title: '缩略图', align: 'center',templet: '#imgTpl'}
                , {fixed: 'right', width: 400, title: '操作', align: 'center', toolbar: '#opeBar'}
            ]]
            ,done: function (res, curr, count) {
                $.each(res.data,function(index,item){
                    $('#view_'+item['good_id']).viewer({
                        url: 'data-original',
                    });
                });
            }
        });

        //搜索表格重载
        var $ = layui.$, active = {
            reload: function () {
                //执行重载
                table.reload('testReload', {
                    page: {
                        curr: 1 //重新从第 1 页开始
                    }
                    , where:$('#layuiForm').parseForm()
                });
            }

        };
        $('.layuiBtn').on('click', function () {
            var type = $(this).data('type');
            active[type] ? active[type].call(this) : '';
        });

    });

</script>
<!--操作模板-->
<script type="text/html" id="opeBar">
    <a href="javascript:location.href = '{:url('update')}?id={{d.good_id}}';" class="btn btn-primary btn-outline btn-xs"><i class="fa fa-paste"></i> 编辑</a>&nbsp;
    <a href="javascript:;" onclick="wk.confirm('{{d.good_id}}','{:url('del')}')" class="btn btn-danger btn-xs m-r-xs"><i class="fa fa-trash-o"></i>删除</a>
    {{# if(d.good_hot == 1){ }}
    <a href="javascript:;" onclick="wk.confirm('{{d.good_id}}','{:url('hot')}','确认上架热门商品?')" class="btn btn-circle btn-xs m-r-xs"><i class="fa fa-paste"></i>热门</a>
    {{# } else if(d.good_hot == 2){}}
    <a href="javascript:;" onclick="wk.confirm('{{d.good_id}}','{:url('delhot')}','确认下架热门商品?')" class="btn btn-default btn-xs m-r-xs"><i class="fa fa-paste"></i>下架热门</a>
    {{# } }}

    {{# if(d.good_top == 1){ }}
    <a href="javascript:;" onclick="wk.confirm('{{d.good_id}}','{:url('top')}','确认上架精品商品?')" class="btn btn-danger btn-xs m-r-xs"><i class="fa fa-paste"></i>精品</a>
    {{# } else if(d.good_top == 2){}}
    <a href="javascript:;" onclick="wk.confirm('{{d.good_id}}','{:url('deltop')}','确认下架精品商品?')" class="btn btn-primary btn-xs m-r-xs"><i class="fa fa-paste"></i>下架精品</a>
    {{# } }}

</script>
<script type="text/html" id="imgTpl">
    <ul onclick="view(this)" id="view_{{d.good_id}}">
        <li><img data-original="{{d.good_thumb}}" src="{{d.good_thumb}}" class="img-circle table-img" onerror="this.src='/static/admin/images/head_default.gif'"  /></li>
    </ul>
</script>

<script type="text/html" id="good_hot">
    {{# if(d.good_hot == 1){ }}
    <span style="color:#ec4758">否</span>
    {{# } else {}}
    <span style="color:#ec4758">是</span>
    {{# } }}
</script>
<script type="text/html" id="good_top">
    {{# if(d.good_top == 1){ }}
    <span style="color:#ec4758">否</span>
    {{# } else {}}
    <span style="color:#ec4758">是</span>
    {{# } }}
</script>
</body>
</html>